package com.example.designmodule.chain;

/**
 * @Author: Dijah
 * @Date: 2023/3/4 11:05
 * @Desc: 处理抽象类
 */
public abstract class code2_Handler {

    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;


    //该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    private code2_Handler nextHandler;

    public code2_Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置请假天数范围
    public code2_Handler(int numStart,int numEnd){
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置上级领导
    public void setNextHandler(code2_Handler nextHandler){
        this.nextHandler = nextHandler;
    }

    //提交请假
    public final void submit(code1_LeaveRequest leave){
        if(0 == this.numStart){
            return;
        }
        //如果请假天数达到该领导者的处理请求
        if(leave.getNum() >= this.numStart){
            this.handleLeave(leave);
            //如果有上级 并且请假天数超过了当前的领导的处理范围
            if(null != this.nextHandler && leave.getNum() > numEnd){
                this.nextHandler.submit(leave);
            }else{
                System.out.println("流程结束");
            }
        }
    }

    //各级领导处理请假方式
    protected abstract void handleLeave(code1_LeaveRequest leave);
}
